package com.tao.service.impl;

import com.tao.mapper.UserMapper;
import com.tao.pojo.User;
import com.tao.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    //通过用户名查询用户
    @Override
    public User findByUsername(String username) {
        User u = userMapper.findByUsername(username);
        return u;
    }

    //新用户注册实现类
    @Override
    public int register(User user) {
        user.setCreateTime(LocalDateTime.now());
        int u = userMapper.register(user);
        return u;
    }

    //更新用户信息
    @Override
    public int update(User user) {
        int i = userMapper.update(user);
        return i;
    }

    @Override
    public int delete(Integer id) {
        int i = userMapper.delete(id);
        return i;
    }

    @Override
    public List<User> selectPage(Integer pageNum, Integer pageSize,String username) {
        List<User> list = userMapper.selectPage(pageNum,pageSize,username);
        return list;
    }

    @Override
    public Integer selectTotal(String username) {
        Integer total = userMapper.selectTotal(username);
        return total;
    }
}
